/** CS2340 Spring 2011 Project
 *  Team: 40 Jiggawatt Hard Driver
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 *
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */

package edu.gatech.jiggawatt.office.gui;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import edu.gatech.jiggawatt.office.model.Patient;
import edu.gatech.jiggawatt.office.model.TreatmentRecord;
import edu.gatech.jiggawatt.office.presenter.Presenter;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Represents "View Patient History" frame
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0
 *
 */
public class ViewPatientHistoryFrame extends JFrame { // $codepro.audit.disable declareDefaultConstructors

	private JPanel contentPane;
	private Presenter presenter;
	private String patientId;

	/**
	 * Create the frame.
	 * @param p presenter
	 * @param id id of patient
	 */
	public ViewPatientHistoryFrame(Presenter p, String id) 
	{
		presenter = p;
		patientId = id;
		
		setTitle("Patient Health History"); // $codepro.audit.disable stringLiterals
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 658, 427); // $codepro.audit.disable numericLiterals
		
		XYSeries series = new XYSeries("Weight");  // $codepro.audit.disable stringLiterals
		
		int visitNumber = 0;
		for (TreatmentRecord tr : ((Patient) presenter.getUser(patientId)).getTreatmentRecords())
		{
			visitNumber++;
			series.add(visitNumber, tr.getWeight());
		}
		
		XYSeriesCollection dataset = new XYSeriesCollection();		
		dataset.addSeries(series);
		
		JFreeChart chart = ChartFactory.createXYLineChart("Patient Weight over time", "visit", "weight", dataset,  // $codepro.audit.disable stringLiterals
				PlotOrientation.VERTICAL, true, true, false);

		
		ChartPanel chartPanel = new ChartPanel(chart);
		chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); // $codepro.audit.disable numericLiterals
				
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); // $codepro.audit.disable numericLiterals
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
			
		JPanel panel = new JPanel();
		panel.setBounds(5, 5, 632, 332); // $codepro.audit.disable numericLiterals
		panel.add(chartPanel);
		contentPane.add(panel);
		
		JButton btnBack = new JButton("Back"); // $codepro.audit.disable stringLiterals
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				setVisible(false);
				dispose();
			}
		});
		btnBack.setBounds(260, 348, 131, 23); // $codepro.audit.disable numericLiterals
		contentPane.add(btnBack);
	}
}
